package com.xhwl.logistics.converter.mapstruct;


import com.xhwl.logistics.dto.http.CardTypeChuangXiangDTO;
import com.xhwl.logistics.entity.VehicleCard;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.NullValueMappingStrategy;

/**
 * 将第三方的车卡信息转换为中台的车卡信息
 */
@Mapper(componentModel = "spring", nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT)
public interface VehicleCardThirdConverter {

    /**
     * 将创享的车卡信息转换为中台的车卡信息
     */
    @Mapping(target = "name", source = "cardTypeChuangXiangDTO.cartypeName")
    @Mapping(target = "cardType", expression = "java(chuangXiangtoCardType(cardTypeChuangXiangDTO.getCartypeName(),null))")
    @Mapping(target = "rechargeMoney", expression = "java(chuangXiangtoCardAmount(cardTypeChuangXiangDTO.getAmount(),null))")
    @Mapping(target = "thirdRuleId", source = "cardTypeChuangXiangDTO.cartypeId")
    VehicleCard chuangXiangtoVehicleCard(CardTypeChuangXiangDTO cardTypeChuangXiangDTO, Integer projectId, String projectName,
                                         Integer parkingLotId, String parkingLotName, String creatorAccountName, String editorAccountName);

    /**
     * 将创享的车卡类型转换为中台的车卡类型
     */
    default Integer chuangXiangtoCardType(String cartypeName,Integer help){
        switch (cartypeName){
            case "月租车":
                return 1;
            case "储值车":
                return 2;
            case "贵宾车":
                return 0;
            case "临时车":
                return 3;
            default:
                return 99;
        }
    }

    /**
     * 将创享的车卡充值金额转换为中台的车卡充值金额，创享的金额单位为元
     */
    default Integer chuangXiangtoCardAmount(Double amount,Integer help){
        amount = amount * 100;
        return amount.intValue();
    }
}
